package com.boc.langxiang.presenter.common;

import com.boc.langxiang.contract.common.OtherSignInContract;
import com.boc.langxiang.entity.request.OtherSignInRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.UserInfo;
import com.boc.langxiang.manager.UserInfoManager;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/12/27.
 */

public class OtherSignInPresenter implements OtherSignInContract, OtherSignInContract.Presenter {
    private View mView;

    public OtherSignInPresenter(View view) {
        this.mView = view;
    }

    @Override
    public void confirm(OtherSignInRequest request) {
        mView.showLoading();
        mService.bindPhoneByPwd(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<UserInfo>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<UserInfo> response) {
                        UserInfo userInfo = response.getContent();
                        UserInfoManager.getInstance().setUserInfo(userInfo);
                        mView.loginSuccess();
                    }
                });
    }
}
